CREATE TABLE `%%GLOBAL_tablePrefix%%categories` (
  `categoryid` int(11) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL default '',
  `description` varchar(255) NOT NULL default '',
  `parentid` int(11) NOT NULL default '0',
  `visits` int(11) NOT NULL default '0',
  `pass` varchar(50) NOT NULL default '',
  `icon` varchar(50) NOT NULL default '',
  `security` enum('public','private') NOT NULL,
  `approvaltype` int(11) NOT NULL default '0',
  `catorder` int(11) NOT NULL default '0',
  PRIMARY KEY  (`categoryid`),
  KEY `%%GLOBAL_tablePrefix%%cat_parentid` (`parentid`),
  KEY `idx_c_name` (`name`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%categoryassociations` (
  `categoryid` int(11) NOT NULL default '0',
  `questionid` int(11) NOT NULL default '0',
  UNIQUE KEY `idx_a_pk` (`categoryid`,`questionid`),
  KEY `idx_ca_questioncategoryids` (`questionid`,`categoryid`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%catassoc_history` (
  `categoryid` int(11) NOT NULL default '0',
  `questionid` int(11) NOT NULL default '0',
  UNIQUE KEY `idx_uqcah_pk` (`categoryid`,`questionid`),
  KEY `idx_cah_questioncategoryids` (`questionid`,`categoryid`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%comments` (
  `commentid` int(11) NOT NULL auto_increment,
  `questionid` int(11) NOT NULL default '0',
  `name` varchar(100) NOT NULL default '',
  `email` varchar(250) NOT NULL default '',
  `content` text NOT NULL,
  `status` enum('pending','approved','disapproved') default 'pending',
  `posted` datetime NOT NULL,
  PRIMARY KEY  (`commentid`),
  KEY `idx_cm_questionid` (`questionid`),
  KEY `idx_cm_status` (`status`),
  KEY `idx_cm_letter` (`content`(5))
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%glossary` (
  `glossaryid` int(11) NOT NULL auto_increment,
  `word` varchar(100) NOT NULL default '',
  `description` text NOT NULL,
  PRIMARY KEY  (`glossaryid`),
  UNIQUE KEY `idx_g_word` (`word`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%groups` (
  `groupid` int(11) NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  `permissions` text NOT NULL,
  `application` text NOT NULL,
  `contactable` tinyint(1) NOT NULL,
  PRIMARY KEY  (`groupid`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%members` (
  `userid` int(11) NOT NULL default '0',
  `groupid` int(11) NOT NULL default '0',
  PRIMARY KEY  (`userid`,`groupid`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%questions` (
  `questionid` int(11) NOT NULL auto_increment,
  `title` varchar(200) NOT NULL default '',
  `answer` longtext NOT NULL,
  `lastupdated` datetime NOT NULL,
  `related` varchar(100) NOT NULL default '',
  `visible` tinyint(1) NOT NULL default '0',
  `sortorder` int(11) NOT NULL default '0',
  `userid` int(11) NOT NULL default '0',
  `views` int(11) NOT NULL default '0',
  `posvotes` int(11) NOT NULL default '0',
  `negvotes` int(11) NOT NULL default '0',
  `score` int(11) NOT NULL default '0',
  `emailed` int(11) NOT NULL default '0',
  `detectrelated` tinyint(1) NOT NULL default '0',
  `metakeywords` varchar(255) NOT NULL,
  `metadescription` text NOT NULL,
  `startdate` datetime NOT NULL,
  `enableexpiry` tinyint(4) NOT NULL,
  `expirydate` datetime NOT NULL,
  `featured` tinyint(1) NOT NULL default '0',
  `workflowstatus` enum('auto_approved','approved','pending', 're_pending', 'disapproved') default 'auto_approved',
  PRIMARY KEY  (`questionid`),
  KEY `idx_q_userid` (`userid`),
  KEY `idx_q_score` (`score`),
  KEY `idx_q_lastupdated` (`lastupdated`),
  KEY `idx_q_title_sortorder` (`title`,`sortorder`),
  FULLTEXT KEY `idx_q_ft` (`title`,`answer`,`metakeywords`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%question_auth` (
  `questionauthid` int(11) NOT NULL auto_increment,
  `questionid` int(11) NOT NULL,
  `groupid` int(11) NOT NULL,
  PRIMARY KEY  (`questionauthid`),
  UNIQUE KEY `questionid` (`questionid`,`groupid`),
  KEY `groupid` (`groupid`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%questions_history` (
  `versionid` int(11) NOT NULL auto_increment,
  `questionid` int(11) NOT NULL default '0',
  `title` varchar(200) NOT NULL default '',
  `answer` text NOT NULL,
  `lastupdated` datetime NOT NULL,
  `related` varchar(100) NOT NULL default '',
  `visible` tinyint(1) NOT NULL default '0',
  `sortorder` int(11) NOT NULL default '0',
  `userid` int(11) NOT NULL default '0',
  `views` int(11) NOT NULL default '0',
  `posvotes` int(11) NOT NULL default '0',
  `negvotes` int(11) NOT NULL default '0',
  `score` int(11) NOT NULL default '0',
  `emailed` int(11) NOT NULL default '0',
  `detectrelated` tinyint(1) NOT NULL default '0',
  `metakeywords` varchar(255) NOT NULL,
  `metadescription` text NOT NULL,
  `startdate` datetime NOT NULL,
  `enableexpiry` tinyint(4) NOT NULL,
  `expirydate` datetime NOT NULL,
  `featured` tinyint(1) NOT NULL default '0',
  `workflowstatus` enum('auto_approved','approved','pending','re_pending','disapproved') default 'auto_approved',
  PRIMARY KEY  (`versionid`),
  KEY `questionid` (`questionid`),
  KEY `lastupdated` (`lastupdated`),
  FULLTEXT KEY `idx_qh_ft` (`title`,`answer`,`metakeywords`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%ratings` (
  `rateid` int(11) NOT NULL auto_increment,
  `questionid` int(11) NOT NULL default '0',
  `ip` varchar(50) NOT NULL default '',
  `ratedat` timestamp NOT NULL,
  `ratingemail` VARCHAR(60) NOT NULL,
  `ratingmessage` VARCHAR(250) NOT NULL,
  PRIMARY KEY  (`rateid`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%searchhistory` (
  `searchstring` varchar(255) NOT NULL default '',
  `amount` int(10) unsigned NOT NULL default '1',
  `numresults` int(11) NOT NULL default '0',
  PRIMARY KEY  (`searchstring`),
  KEY `sh_num_res` (`numresults`),
  FULLTEXT KEY `sh_ss_ft_idx` (`searchstring`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%submittedquestions` (
  `subquestid` int(11) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL default '',
  `email` varchar(250) NOT NULL default '',
  `subject` varchar(250) NOT NULL default '',
  `message` text NOT NULL,
  `posted` datetime NOT NULL,
  PRIMARY KEY  (`subquestid`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%subscribers` (
  `subscriberid` int(11) NOT NULL auto_increment,
  `questionid` int(11) NOT NULL,
  `email` varchar(255) NOT NULL,
  `subscribedate` datetime NOT NULL,
  `confirmed` tinyint(1) NOT NULL,
  `confirmcode` varchar(32) NOT NULL,
  PRIMARY KEY  (`subscriberid`),
  UNIQUE KEY `idx_s_questionid_email` (`questionid`,`email`),
  KEY `questionid` (`questionid`),
  KEY `email_confirmcode` (`email`,`confirmcode`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%users` (
  `userid` int(11) NOT NULL auto_increment,
  `username` varchar(50) NOT NULL default '',
  `pass` varchar(32) NOT NULL default '',
  `firstname` varchar(50) NOT NULL default '',
  `lastname` varchar(50) NOT NULL default '',
  `status` tinyint(1) NOT NULL default '0',
  `email` varchar(255) NOT NULL default '',
  `forgotpasscode` varchar(32) NOT NULL default '',
  `sessionid` varchar(32) NOT NULL default '',
  `tokencode` varchar(128) NOT NULL default '',
  PRIMARY KEY  (`userid`),
  UNIQUE KEY `username` (`username`),
  KEY `status` (`status`)
) ENGINE=MyISAM;

CREATE TABLE `%%GLOBAL_tablePrefix%%customfields` (
  `customfieldid` int(11) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL,
  `type` enum('multi_check','freeform') NOT NULL,
  PRIMARY KEY  (`customfieldid`)
);

CREATE TABLE `%%GLOBAL_tablePrefix%%customfields_data` (
  `customfield_dataid` int(11) NOT NULL auto_increment,
  `customfieldid` int(11) NOT NULL,
  `data` varchar(250) NOT NULL,
  PRIMARY KEY  (`customfield_dataid`),
  KEY `customfieldid` (`customfieldid`)
);

CREATE TABLE `%%GLOBAL_tablePrefix%%questions_customfields` (
  `questions_customfieldsid` int(11) NOT NULL auto_increment,
  `questionid` int(11) NOT NULL,
  `customfieldid` int(11) NOT NULL,
  `data` varchar(250) NOT NULL,
  PRIMARY KEY  (`questions_customfieldsid`),
  KEY `questionid` (`questionid`),
  KEY `customfieldid` (`customfieldid`)
);

CREATE TABLE `%%GLOBAL_tablePrefix%%newss` (
  `newsid` int(11) NOT NULL auto_increment,
  `title` varchar(200) NOT NULL default '',
  `content` longtext NOT NULL,
  `lastupdated` datetime NOT NULL,
  `visible` tinyint(1) NOT NULL default '0',
  `userid` int(11) NOT NULL default '0',
  PRIMARY KEY  (`newsid`)
) ENGINE=MyISAM;

 CREATE TABLE `%%GLOBAL_tablePrefix%%pageindex` (
	`pageindexid` int(11) NOT NULL auto_increment,
	`fullurl` VARCHAR( 500 ) NOT NULL ,
	`questionid` INT NOT NULL ,
	`content` LONGTEXT NOT NULL ,
	`plugin` VARCHAR( 255 ) NOT NULL ,
	`filename` VARCHAR( 255 ) NOT NULL ,
	`lastupdated` DATETIME NOT NULL ,
	PRIMARY KEY ( `pageindexid` ),
	UNIQUE KEY `idx_pi_fullurl` (`fullurl` ( 255 )),
	KEY `idx_pi_lastupdated` (`lastupdated`),
	FULLTEXT KEY `idx_pi_ft` (`content`,`filename`)
) ENGINE=MyISAM;

 CREATE TABLE `%%GLOBAL_tablePrefix%%userlogin` (
	`ipaddress` VARCHAR( 100 ) NOT NULL ,
	`attemptnum` INT NOT NULL ,
	`tslogin` DATETIME NOT NULL ,
	UNIQUE KEY `idx_userlogin_ui_ip` (`ipaddress`)
) ENGINE=MyISAM;
